/*
  The JWare Public Access Project - http://jware.public.org

  Copyright (c) 2012-OCT J. Paul Jackson

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA
*/


package org.jware.ClassBuilder;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 * This file is the edited UI generated by NetBeans
 *
 * @author Paul Jackson<jjacks@email.cpcc.edu>
 */
public class ClassBuilder extends javax.swing.JFrame {
    private static final long serialVersionUID = 1L;

    // The generator
    ClassGenerator classGenerator;
    /**
     * Creates new form ClassBuilder
     */
    
 //   String className="";
    
    public ClassBuilder() {
        classGenerator = new ClassGenerator();
        classGenerator.createLists();
        
        initComponents();
    }
    
    // Create a big string from UI components to define class.
    private void generate() {
        StringBuilder sb=new StringBuilder();     
        String classAccess;

        sb.append("");
        if (publicAccessRadio.isSelected()) {
            classAccess=publicAccessRadio.getText().toLowerCase();
        } else 
            classAccess=privateAccessRadio.getText().toLowerCase();
        
        if (abstractModifierCheck.isSelected()) {
           sb.append(abstractModifierCheck.getText().toLowerCase()).append(" ");
        }
        if (finalModifierCheck.isSelected()) {
           sb.append(finalModifierCheck.getText().toLowerCase()).append(" ");
        }
        if (staticModfierCheck.isSelected()) {
           sb.append(staticModfierCheck.getText().toLowerCase()).append(" ");
        }
        
        String packageN=packageNameText.getText();
        if(!"".equals(packageN))
            classGenerator.setPackage(packageN);
        
        String className=classNameTextField.getText();
        String classSuperName=superClassTextBox.getText();
        String interfaceName=interfaceTextBox.getText();
        classGenerator.setClassName(classAccess, sb.toString(), className, classSuperName, interfaceName); 
        
        for (int row=0; row<variablesTable.getModel().getRowCount();row++) {
                String varAccess=(String)variablesTable.getValueAt(row, 0);
                String varModifier=(String)variablesTable.getValueAt(row, 1);
                if ("default".equals(varModifier)) 
                    varModifier="";
                String varType=(String)variablesTable.getValueAt(row, 2);
                String varName=(String)variablesTable.getValueAt(row, 3);
                classGenerator.createVariable(varAccess, varModifier, varType, varName);
        }
         for (int row=0; row<methodTable.getModel().getRowCount();row++) {
                String methodAccess=(String)methodTable.getValueAt(row, 0);
                String methodModifier=(String)methodTable.getValueAt(row, 1);
                if ("default".equals(methodModifier)) 
                    methodModifier="";
                String methodType=(String)methodTable.getValueAt(row, 2);
                String methodName=(String)methodTable.getValueAt(row, 3);
                classGenerator.createMethod(methodAccess, methodModifier, methodType, methodName);
        }
        classGenerator.generateClass();
        

    }

    //  This stuff was generated from NetBeans.
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jFrame1 = new javax.swing.JFrame();
        jScrollPane1 = new javax.swing.JScrollPane();
        displayTextArea = new javax.swing.JTextArea();
        fileChooser = new javax.swing.JFileChooser();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        classNameTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        packageNameText = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        abstractModifierCheck = new javax.swing.JCheckBox();
        finalModifierCheck = new javax.swing.JCheckBox();
        staticModfierCheck = new javax.swing.JCheckBox();
        jLabel6 = new javax.swing.JLabel();
        publicAccessRadio = new javax.swing.JRadioButton();
        privateAccessRadio = new javax.swing.JRadioButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel7 = new javax.swing.JLabel();
        superClassTextBox = new javax.swing.JTextField();
        constructorFromSuperCheckBox = new javax.swing.JCheckBox();
        jLabel8 = new javax.swing.JLabel();
        addVariableButton = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        addMethodButton = new javax.swing.JButton();
        removeMethodButton = new javax.swing.JButton();
        removeVariableButton = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        methodTable = new javax.swing.JTable();
        jScrollPane6 = new javax.swing.JScrollPane();
        variablesTable = new javax.swing.JTable();
        generateCommentsVariableCheck = new javax.swing.JCheckBox();
        generateCommentMethodsBox = new javax.swing.JCheckBox();
        jLabel11 = new javax.swing.JLabel();
        interfaceTextBox = new javax.swing.JTextField();
        generateGetSetCheck = new javax.swing.JCheckBox();
        jLabel14 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        generateButton = new javax.swing.JButton();
        doneButton = new javax.swing.JButton();
        toScreenButton = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();

        jFrame1.setTitle("Class Definition");
        jFrame1.setName("classDefinitionFrame"); // NOI18N

        displayTextArea.setEditable(false);
        displayTextArea.setColumns(20);
        displayTextArea.setLineWrap(true);
        displayTextArea.setRows(5);
        jScrollPane1.setViewportView(displayTextArea);

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );

        fileChooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
        fileChooser.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Class Name:");

        classNameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                classNameTextFieldActionPerformed(evt);
            }
        });

        jLabel4.setText("Package:");

        packageNameText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                packageNameTextActionPerformed(evt);
            }
        });

        jLabel5.setText("Modifiers:");

        abstractModifierCheck.setText("Abstract");
        abstractModifierCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                abstractModifierCheckActionPerformed(evt);
            }
        });

        finalModifierCheck.setText("Final");

        staticModfierCheck.setText("Static");

        jLabel6.setText("Access:");

        buttonGroup1.add(publicAccessRadio);
        publicAccessRadio.setSelected(true);
        publicAccessRadio.setText("Public");
        publicAccessRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                publicAccessRadioActionPerformed(evt);
            }
        });

        buttonGroup1.add(privateAccessRadio);
        privateAccessRadio.setText("Private");

        jLabel7.setText("Super Class:");

        superClassTextBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                superClassTextBoxActionPerformed(evt);
            }
        });

        constructorFromSuperCheckBox.setText("Constructor from superclass");
        constructorFromSuperCheckBox.setEnabled(false);
        constructorFromSuperCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                constructorFromSuperCheckBoxActionPerformed(evt);
            }
        });

        jLabel8.setText("Variables:");

        addVariableButton.setText("Add...");
        addVariableButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addVariableButtonActionPerformed(evt);
            }
        });

        jLabel9.setText("Methods:");

        addMethodButton.setText("Add...");
        addMethodButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addMethodButtonActionPerformed(evt);
            }
        });

        removeMethodButton.setText("Remove");
        removeMethodButton.setEnabled(false);
        removeMethodButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeMethodButtonActionPerformed(evt);
            }
        });

        removeVariableButton.setText("Remove");
        removeVariableButton.setEnabled(false);
        removeVariableButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeVariableButtonActionPerformed(evt);
            }
        });

        methodTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Access", "Modifier", "Returns", "Name"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        methodTable.getTableHeader().setReorderingAllowed(false);
        jScrollPane5.setViewportView(methodTable);
        methodTable.getColumnModel().getColumn(0).setResizable(false);
        methodTable.getColumnModel().getColumn(1).setResizable(false);
        methodTable.getColumnModel().getColumn(2).setResizable(false);
        methodTable.getColumnModel().getColumn(3).setResizable(false);
        TableColumn accessColumn1 = methodTable.getColumnModel().getColumn(0);
        JComboBox comboBox1 = new JComboBox();
        comboBox1.addItem("public");
        comboBox1.addItem("private");
        comboBox1.addItem("protected");
        accessColumn1.setCellEditor(new DefaultCellEditor(comboBox1));
        TableColumn modColumn1 = methodTable.getColumnModel().getColumn(1);
        JComboBox modBox1 = new JComboBox();
        modBox1.addItem("default");
        modBox1.addItem("abstract");
        modBox1.addItem("static");
        modBox1.addItem("final");
        modColumn1.setCellEditor(new DefaultCellEditor(modBox1));
        TableColumn typeColumn1 = methodTable.getColumnModel().getColumn(2);
        JComboBox typeBox1 = new JComboBox();
        typeBox1.addItem("void");
        typeBox1.addItem("int");
        typeBox1.addItem("float");
        typeBox1.addItem("double");
        typeBox1.addItem("String");
        typeBox1.addItem("char");
        typeBox1.addItem("boolean");
        typeColumn1.setCellEditor(new DefaultCellEditor(typeBox1));

        variablesTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Access", "Modifier", "Type", "Name"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        variablesTable.getTableHeader().setReorderingAllowed(false);
        jScrollPane6.setViewportView(variablesTable);
        variablesTable.getColumnModel().getColumn(0).setResizable(false);
        variablesTable.getColumnModel().getColumn(1).setResizable(false);
        variablesTable.getColumnModel().getColumn(2).setResizable(false);
        variablesTable.getColumnModel().getColumn(3).setResizable(false);
        TableColumn accessColumn = variablesTable.getColumnModel().getColumn(0);
        JComboBox comboBox = new JComboBox();
        comboBox.addItem("public");
        comboBox.addItem("private");
        comboBox.addItem("protected");
        accessColumn.setCellEditor(new DefaultCellEditor(comboBox));
        TableColumn modColumn = variablesTable.getColumnModel().getColumn(1);
        JComboBox modBox = new JComboBox();
        modBox.addItem("default");
        modBox.addItem("static");
        modBox.addItem("final");
        modColumn.setCellEditor(new DefaultCellEditor(modBox));
        TableColumn typeColumn = variablesTable.getColumnModel().getColumn(2);
        JComboBox typeBox = new JComboBox();
        typeBox.addItem("int");
        typeBox.addItem("float");
        typeBox.addItem("double");
        typeBox.addItem("String");
        typeBox.addItem("char");
        typeBox.addItem("boolean");
        typeColumn.setCellEditor(new DefaultCellEditor(typeBox));

        generateCommentsVariableCheck.setText("Generate Comments");

        generateCommentMethodsBox.setText("Generate Comments");

        jLabel11.setText("Interface/s:");

        generateGetSetCheck.setText("Generate Getters/Setters");
        generateGetSetCheck.setActionCommand("Generate getters/setters");
        generateGetSetCheck.setEnabled(false);
        generateGetSetCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generateGetSetCheckActionPerformed(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Tahoma", 2, 7)); // NOI18N
        jLabel14.setText("Use commas to separate multiple interfaces.");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel1)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(10, 10, 10)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(classNameTextField)
                    .addComponent(superClassTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(constructorFromSuperCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(packageNameText, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14)
                            .addComponent(interfaceTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(80, 80, 80)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(abstractModifierCheck, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(finalModifierCheck)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(staticModfierCheck, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(publicAccessRadio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(privateAccessRadio)
                        .addGap(79, 79, 79)))
                .addGap(173, 173, 173))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSeparator1)
                .addContainerGap())
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(removeVariableButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(addVariableButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(11, 11, 11)
                                .addComponent(generateCommentMethodsBox)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(addMethodButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(removeMethodButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(generateCommentsVariableCheck)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(generateGetSetCheck)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(classNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel4)
                    .addComponent(packageNameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(publicAccessRadio, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(privateAccessRadio, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(finalModifierCheck, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(staticModfierCheck, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(abstractModifierCheck, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(constructorFromSuperCheckBox, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(4, 4, 4)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(superClassTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel11)
                    .addComponent(interfaceTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(generateCommentsVariableCheck)
                    .addComponent(generateGetSetCheck))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(addVariableButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(removeVariableButton)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(generateCommentMethodsBox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(addMethodButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(removeMethodButton))
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setForeground(new java.awt.Color(255, 255, 255));

        jLabel2.setFont(new java.awt.Font("Arial Black", 0, 18)); // NOI18N
        jLabel2.setText("Class Builder Wizard");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setText("Create a new class");

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jware/ClassBuilder/java_logo_3.jpg"))); // NOI18N

        jLabel12.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        jLabel12.setText("For Processing");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel3)
                        .addGap(53, 53, 53)))
                .addComponent(jLabel10)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(1, 1, 1)))
                .addComponent(jLabel3)
                .addContainerGap())
        );

        generateButton.setText("Save to file...");
        generateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generateButtonActionPerformed(evt);
            }
        });

        doneButton.setText("Done");
        doneButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                doneButtonActionPerformed(evt);
            }
        });

        toScreenButton.setText("View...");
        toScreenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                toScreenButtonActionPerformed(evt);
            }
        });

        resetButton.setText("Reset");
        resetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(resetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(toScreenButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(generateButton)
                .addGap(18, 18, 18)
                .addComponent(doneButton, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(10, 10, 10))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(doneButton)
                    .addComponent(generateButton)
                    .addComponent(toScreenButton)
                    .addComponent(resetButton))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void doneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doneButtonActionPerformed
        System.exit(0);
    }//GEN-LAST:event_doneButtonActionPerformed

 
    // User clicked the generate button, I used the cool pre-defined FileChooser class!
    private void generateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateButtonActionPerformed

        // Initialized from the UI above.
        String cName=classNameTextField.getText();
        File file;
        // This is a utility method called above to create the file data.
        generate();
        // If the className has not been initialized then use the 'Temp' name.
        if(!"".equals(cName)) {
            file = new File(cName+".java");
        } else 
            file = new File("Temp.java");
        
        // Set the file name in UI file name field. 
        fileChooser.setSelectedFile(file);
        // Display the save dialog.
        int returnVal = fileChooser.showSaveDialog(ClassBuilder.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            // Make sure we have the file 
            file = fileChooser.getSelectedFile();
            // Use the Path class to get an acceptable path  
            // for creating or overwriting the file.
            Path path = file.toPath();
            // Get the data, write it out 
            byte[] buf = classGenerator.getClassDef().getBytes();
            try{ 
                Files.write(path, buf,StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); 
                System.out.println("Saving: " + file.getName() + ".");
            } catch(IOException e){
                System.out.println("Error. " + e);
            }
         }
    }//GEN-LAST:event_generateButtonActionPerformed

    private void generateGetSetCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateGetSetCheckActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_generateGetSetCheckActionPerformed

    private void removeVariableButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeVariableButtonActionPerformed

    }//GEN-LAST:event_removeVariableButtonActionPerformed

    private void removeMethodButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeMethodButtonActionPerformed

    }//GEN-LAST:event_removeMethodButtonActionPerformed

    private void addMethodButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMethodButtonActionPerformed
        DefaultTableModel model = (DefaultTableModel) methodTable.getModel();
        model.addRow(new Object[]{" ", " ", " "," "});
    }//GEN-LAST:event_addMethodButtonActionPerformed

    private void addVariableButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addVariableButtonActionPerformed
        DefaultTableModel model = (DefaultTableModel) variablesTable.getModel();
        model.addRow(new Object[]{" ", " ", " "," "});
    }//GEN-LAST:event_addVariableButtonActionPerformed

    private void constructorFromSuperCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_constructorFromSuperCheckBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_constructorFromSuperCheckBoxActionPerformed

    private void superClassTextBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_superClassTextBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_superClassTextBoxActionPerformed

    private void publicAccessRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_publicAccessRadioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_publicAccessRadioActionPerformed

    private void abstractModifierCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_abstractModifierCheckActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_abstractModifierCheckActionPerformed

    private void packageNameTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_packageNameTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_packageNameTextActionPerformed

    private void classNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_classNameTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_classNameTextFieldActionPerformed

    private void toScreenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_toScreenButtonActionPerformed

    jFrame1.pack();
    jFrame1.setVisible(true);
    generate();
    displayTextArea.setText(classGenerator.getClassDef());
    
        }//GEN-LAST:event_toScreenButtonActionPerformed

    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
        // TODO add your handling code here:
        classGenerator.reset();
    }//GEN-LAST:event_resetButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ClassBuilder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ClassBuilder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ClassBuilder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ClassBuilder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ClassBuilder().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox abstractModifierCheck;
    private javax.swing.JButton addMethodButton;
    private javax.swing.JButton addVariableButton;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTextField classNameTextField;
    private javax.swing.JCheckBox constructorFromSuperCheckBox;
    private javax.swing.JTextArea displayTextArea;
    private javax.swing.JButton doneButton;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JCheckBox finalModifierCheck;
    private javax.swing.JButton generateButton;
    private javax.swing.JCheckBox generateCommentMethodsBox;
    private javax.swing.JCheckBox generateCommentsVariableCheck;
    private javax.swing.JCheckBox generateGetSetCheck;
    private javax.swing.JTextField interfaceTextBox;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable methodTable;
    private javax.swing.JTextField packageNameText;
    private javax.swing.JRadioButton privateAccessRadio;
    private javax.swing.JRadioButton publicAccessRadio;
    private javax.swing.JButton removeMethodButton;
    private javax.swing.JButton removeVariableButton;
    private javax.swing.JButton resetButton;
    private javax.swing.JCheckBox staticModfierCheck;
    private javax.swing.JTextField superClassTextBox;
    private javax.swing.JButton toScreenButton;
    private javax.swing.JTable variablesTable;
    // End of variables declaration//GEN-END:variables
}
